<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    modelValue: { type: Number, required: true },
    tabs: { type: Array, required: true },
    labelKey: String,
    col: Number,
  },
  emits: {
    "update:modelValue": (value: number) => typeof value === "number",
  },
  setup(props, ctx) {
    return {
      tabClick: (value: number) => ctx.emit("update:modelValue", value),
    };
  },
});
</script>

<template>
  <div class="tab">
    <div
      class="tab-item"
      :class="col ? 'tab-item-even' : 'tab-item-space'"
      :style="{ width: col ? `${100 / col}%` : '', flexGrow: col ? '' : 1 }"
      v-for="(i, d) of tabs"
      :key="d"
      @click="tabClick(d)"
    >
      <div style="position: relative">
        <div
          class="tab-item-text"
          :class="{ 'tab-item-active': d === modelValue }"
        >
          {{ i }}
        </div>
        <div class="tab-item-line" v-if="d === modelValue"></div>
      </div>
    </div>
  </div>
</template>

<style lang="less">
.tab {
  display: flex;
  justify-content: flex-start;
  width: 100%;
  height: 40px;

  .tab-item {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex-shrink: 0;
    height: 100%;
    padding-top: 8px;
    box-sizing: border-box;
  }

  .tab-item-text {
    font-size: 14px;
    color: #666666;
    line-height: 24px;
    text-align: center;
    white-space: nowrap;
  }

  .tab-item-active {
    font-size: 16px;
    color: #333333;
    font-weight: bold;
  }

  .tab-item-line {
    position: absolute;
    left: 50%;
    top: 100%;
    width: 18px;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(90deg, #1bc76f 0%, #ade1c5 100%);
    transform: translateX(-50%);
  }

  .tab-item-even {
    flex-grow: 1;
  }

  .tab-item-space {
    margin-right: 15px;
  }
}
</style>
